/*
 * Copyright (c) 2020 - present, Inspur Genersoft Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.inspur.edp.cef.generator.apiGenerator.dataType.entityInterface.dataTypeInfo;

import com.inspur.edp.caf.generator.BaseGenerator;
import com.inspur.edp.caf.generator.baseInfo.TypeInfo;
import com.inspur.edp.caf.generator.item.ClassGenerator;
import com.inspur.edp.caf.generator.item.ClassGeneratorContext;
import com.inspur.edp.caf.generator.property.ClassPropertyGenerator;
import com.inspur.edp.caf.generator.property.PropertyGenerator;
import com.inspur.edp.cef.designtime.api.IGspCommonDataType;
import com.inspur.edp.cef.designtime.api.IGspCommonField;
import com.inspur.edp.cef.gencommon.MediateType;
import com.inspur.edp.cef.generator.apiGenerator.dataType.entityInterface.DataTypeInterfaceGeneratorContext;
import com.inspur.edp.cef.generator.apiGenerator.dataType.entityInterface.propertyInfo.DataTypePropInfoGenerator;
import com.inspur.edp.cef.generator.apiGenerator.dataType.mgrInterface.mgrInfo.DisplayValueKeyPropGen;
import com.inspur.edp.cef.spi.entity.info.AbstractDataTypeInfo;
import java.util.List;
import java.util.stream.Collectors;
import org.eclipse.jdt.core.dom.Modifier.ModifierKeyword;

public class DataTypeInfoGenerator extends ClassGenerator
{
	protected DataTypeInterfaceGeneratorContext parentContext;
	protected IGspCommonDataType dataType;

	public DataTypeInfoGenerator(DataTypeInterfaceGeneratorContext parentContext)
	{
		super(parentContext.getApiGenContext().getCompilationUnitInfo());
		this.parentContext = parentContext;
		this.dataType = parentContext.getDataType();
	}


//ORIGINAL LINE: protected new DataTypeInfoGeneratorContext getContext() { return (DataTypeInfoGeneratorContext)((super.getContext() instanceof DataTypeInfoGeneratorContext) ? super.getContext() : null); }
	@Override
	protected DataTypeInfoGeneratorContext getContext() { return (DataTypeInfoGeneratorContext)((super.getContext() instanceof DataTypeInfoGeneratorContext) ? super.getContext() : null); }


		///#region sealed
	@Override
	protected final TypeInfo setParentClass()
	{
		java.lang.Class type = getParentClassType();
		if (!AbstractDataTypeInfo.class.isAssignableFrom(type))
		{
			throw new RuntimeException("DataTypeInfoGenerator生成器的生成基类应为AbstractDataTypeInfo及其子类。");
		}
		return new TypeInfo(type.getName());
	}

	@Override
	protected final java.util.ArrayList<ModifierKeyword>  getAccessModifier() { return new java.util.ArrayList<ModifierKeyword>(java.util.Arrays.asList(new ModifierKeyword[] { ModifierKeyword.PUBLIC_KEYWORD })); }

	@Override
	protected final java.util.ArrayList<BaseGenerator>  createClassExtendChildGenrators()
	{
		java.util.ArrayList<BaseGenerator> list = new java.util.ArrayList<BaseGenerator>();
		//字段
		List<BaseGenerator> eleGenList = dataType.getContainElements().stream().map(el -> (BaseGenerator)createPropInfoGenerator(el)).collect(Collectors.toList());
		if (eleGenList != null && eleGenList.size() > 0)
		{
			list.addAll(eleGenList);
		}
		//扩展
		java.util.ArrayList<BaseGenerator> extendList = createExtendChildGenerators();
		if (extendList!=null && extendList.size()>0)
		{
			list.addAll(extendList);
		}
		return list;
	}

	@Override
	protected final java.util.ArrayList<ClassPropertyGenerator>  createPropertyGenerators()
	{

		java.util.ArrayList<ClassPropertyGenerator> list = super.createPropertyGenerators();
    if (list == null) {
      list = new java.util.ArrayList<ClassPropertyGenerator>();
		}
		//TODO: Java版临时注释 国际化优先级低
		// public override string getDispalyValueKey() { return ""; }
		DisplayValueKeyPropGen displayKeyPropGen = new DisplayValueKeyPropGen(dataType.getI18nResourceInfoPrefix().concat(".").concat("Name"));
		list.add(displayKeyPropGen);
		// ProptyInfoTypes
		DataTypeProptyInfoTypesDicGen propInfoTypes = new DataTypeProptyInfoTypesDicGen(getContext());
		list.add(propInfoTypes);
		// 扩展
		java.util.ArrayList<ClassPropertyGenerator> extendProps = createExtendPropertyGenerators();
		if (extendProps != null && extendProps.size()>0)
		{
			list.addAll(extendProps);
		}
		return list;
	}


		///#endregion

	@Override
	protected void  beforeInitialize()
	{
		super.beforeInitialize();
		parentContext.setDataTypeInfoType(new MediateType(parentContext.getApiGenContext().getCompilationUnitInfo().getPackageName(), getName()));
	}


	@Override
	protected String  getName() { return dataType.getCode().concat("DataTypeInfo"); }

	@Override
	protected ClassGeneratorContext createClassInfoContext()
	{
		return new DataTypeInfoGeneratorContext(parentContext);
	}


	protected DataTypePropInfoGenerator createPropInfoGenerator(IGspCommonField field) { return new DataTypePropInfoGenerator(getContext(), field); }



	protected java.util.ArrayList<ClassPropertyGenerator>  createExtendPropertyGenerators() { return null; }


	protected java.util.ArrayList<BaseGenerator>  createExtendChildGenerators() { return null; }

	protected java.lang.Class  getParentClassType()
	{
		return AbstractDataTypeInfo.class;
	}
}
